/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				StopBOPlan
 
Function						: 				Provides a Plan for sending 
 												a stop command 
****************************************************************************/
package planninglanguage.plans;


import org.jdom.Element;

import planninglanguage.conditions.Condition;
import planninglanguage.conditions.StatusCondition;
import planninglanguage.conditions.UnitExistsCondition;
import util.XMLWriter;

public class StopBOPlan extends BasicOperatorPlan implements Cloneable {
	
	public StopBOPlan(int a_unitID,Condition a_precondition,Condition a_aliveCondition,Condition a_successCondition)
	{
		super(a_precondition,a_aliveCondition,a_successCondition);
		m_unitID=a_unitID;
		m_precondition = new UnitExistsCondition(m_unitID);
		m_aliveCondition = new UnitExistsCondition(m_unitID);
		m_successCondition = new StatusCondition(m_unitID,"idle");
	}
	
	public StopBOPlan(int a_unitID,Condition a_precondition,Condition a_aliveCondition,Condition a_successCondition, Plan a_parent)
	{
		super(a_precondition,a_aliveCondition,a_successCondition);
		m_unitID=a_unitID;
		m_precondition = new UnitExistsCondition(m_unitID);
		m_aliveCondition = new UnitExistsCondition(m_unitID);
		m_successCondition = new StatusCondition(m_unitID,"idle");
		m_parent = a_parent;
	}
	
	public boolean send()
	{
		// to-do:
		// send the stop command to ABL
		// ...
		
		return true;
	}
	
	public Object clone()
	{
		StopBOPlan l_p=new StopBOPlan(m_unitID,null,null,null, m_parent);
		l_p.setContext(m_context);
		l_p.m_originalUnit = m_originalUnit;
		return l_p;
	}
	
	public String toString(int tabs) {
		String str= "";
		int i;
		
		for(i=0;i<tabs;i++) str = str + "  ";
		str = str + "StopBOPlan(status = " + STATUS_NAME[m_status] + " , unitID = " + m_unitID + " ) ";
		str = str + conditionsToString(tabs);
		return str;
	}	
	
	public boolean sameGoal(Object other)
	{
		if (getClass() != other.getClass()) return false;

		StopBOPlan o = (StopBOPlan) other;
		   
		if (m_unitID!=o.m_unitID) return false;		   
		return true;
	}		
	
	public void writeXML(XMLWriter w) {
		w.tag(super.XMLopenTag() + " type=\"" + 
				this.getClass().getSimpleName() + "\"");		
		{
			super.writeBOPlanAttrsXML(w);
		}
		w.tag(super.XMLcloseTag());
	}
	
	protected static StopBOPlan loadFromXML(Element e) {
		StopBOPlan plan = new StopBOPlan(-1, null, null, null);
		return plan;
	}
	
}
